package com.zxmc.aop;

import com.zxmc.common.utils.BloomFilterUtil;
import com.zxmc.pojo.dto.NovelQueryDto;
import com.zxmc.pojo.dto.PageNovelQueryDto;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class BloomFilterAddAspect {

    @Autowired
    private BloomFilterUtil bloomFilterUtil;

    @After("@annotation(BloomFilterAdd)")
    public void after(JoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        BloomFilterAdd bloomFilterAdd = method.getAnnotation(BloomFilterAdd.class);
        String filterName = bloomFilterAdd.value();

        // 获取方法的第一个参数作为布隆过滤器的 key
        Object[] args = joinPoint.getArgs();
        if (args.length > 0) {
            String key=BloomFilterAspect.getKey(args);
            bloomFilterUtil.add(key);

        }
    }
}
